﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class LanguagesResponseContext : BaseResponseContext
	{
		IList<Language> languages = null;
		public override void SetContext(object context)
		{
			if (context == null)
				return;

			base.SetContext(context);


			XmlNode languagesnodes = document.SelectSingleNode("//Languages");

			ParseExtendedInfo(languagesnodes);

			XmlNodeList nodes = document.SelectNodes("//Languages/Language");

			languages = new List<Language>();

			foreach (XmlNode node in nodes)
			{
				Language lang = new Language();
				if (node.Attributes["langId"] != null)
					lang.LanguageId = node.Attributes["langId"].Value;
				if (node.Attributes["langName"] != null)
					lang.LanguageName = node.Attributes["langName"].Value;
				languages.Add(lang);
			}

			FireChanges();
		}

		public override object GetContext()
		{
			return languages;
		}
	}
}